#ifndef __GT9147_H__
#define __GT9147_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

#define T_IIC_PORT GPIOG
#define T_IIC_PORT_ENABLE() do{__HAL_RCC_GPIOG_CLK_ENABLE();}while(0) 

#define T_SCK_PIN GPIO_PIN_6
#define T_SDA_PIN GPIO_PIN_3
#define T_RST_PIN GPIO_PIN_8
#define T_INT_PIN GPIO_PIN_7

/* GT9147 capacitive touch controller driver API */

/*
 * Send configuration parameters to GT9147.
 * mode: 0 - do not save to flash; 1 - save to flash
 * return: 0 on success; non-zero on failure
 */
uint8_t GT9147_Send_Cfg(uint8_t mode);

/*
 * Write registers of GT9147.
 * reg: start register address
 * buf: data buffer
 * len: number of bytes to write
 * return: 0 on success; non-zero on failure
 */
uint8_t GT9147_WR_Reg(uint16_t reg, uint8_t *buf, uint8_t len);

/*
 * Read registers of GT9147.
 * reg: start register address
 * buf: receive buffer
 * len: number of bytes to read
 */
void GT9147_RD_Reg(uint16_t reg, uint8_t *buf, uint8_t len);

/*
 * Initialize GT9147 device.
 * return: 0 on success; non-zero on failure
 */
uint8_t GT9147_Init(void);

/*
 * Scan touch status (polling mode).
 * mode: 0 for normal scan (implementation may use as temp variable)
 * return: 0 - no touch; 1 - touch detected
 */
uint8_t GT9147_Scan(uint8_t mode);

#ifdef __cplusplus
}
#endif

#endif /* __GT9147_H__ */